import {Injectable} from '@angular/core';
import {Http, Headers,URLSearchParams} from '@angular/http';

@Injectable()
export class LoginService {

    private _loginUrl: string = "http://localhost:8001/login";


    constructor(private _http: Http) {


    }

    login(username,password){
        var creds = "username=" + username + "&password=" + password;
        var headers = new Headers();
        headers.append('Content-Type', 'application/x-www-form-urlencoded');
        this._http.post(this._loginUrl,creds,{headers:headers,withCredentials: true})
            .subscribe(data => console.log(data),err => console.log(err),() => console.log('Register Complete'))
    }

    queryAdd(){
        var queryUrl = "http://localhost:8001/consul/add"
        let  params = new URLSearchParams();
        params.set("a","1");
        params.set("b","2");
        this._http.get(queryUrl,{withCredentials: true,search:params})
            .subscribe(data => console.log(data),err => console.log(err),() => console.log('Register Complete'))
    }


}